package com.itplh.modules.shirojwt.service.impl;

import com.itplh.modules.shirojwt.constants.OAuthConstant;
import com.itplh.modules.shirojwt.pojo.ShiroJwtUser;
import com.itplh.modules.shirojwt.service.ShiroJwtUserService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @Description:
 * @Author: tanpeng
 * @Date: 2019-07-10 22:34
 * @Version: V1.0
 */
@Service
public class ShiroJwtUserServiceImpl implements ShiroJwtUserService {

  @Override
  public ShiroJwtUser findByUserName(String userName) {
    if (!StringUtils.isEmpty(userName) && ("tanpeng".equals(userName))) {
      return getShiroJwtUser();
    }
    return null;
  }

  /**
   * 写死验证业务
   *
   * @return ShiroJwtUser
   */
  private ShiroJwtUser getShiroJwtUser() {
    Set<String> roles = new LinkedHashSet<>();
    roles.add(OAuthConstant.Roles.ADMIN);

    Set<String> permissions = new LinkedHashSet<>();
    permissions.add(OAuthConstant.Permissions.SELECT);
    permissions.add(OAuthConstant.Permissions.INSERT);

    ShiroJwtUser loginUser = ShiroJwtUser.builder()
            .username("tanpeng")
            .password("123456")
            .roles(roles)
            .permissions(permissions)
            .build();
    return loginUser;
  }

}
